import 'package:get/get.dart';

import '../common/api_service.dart';
import '../model/cartoon_model.dart';

class FollowingController extends GetxController {
  final List<CartoonModel> cartoonList = [];

  bool isLoading = false;
  bool isShowEmpty = false;
  bool isShowError = false;

  @override
  void onInit() {
    super.onInit();

    _showLoading();
    _getFollowedCartoons();
  }

  void _getFollowedCartoons() {
    ApiService().getFollowedCartoons((list) {
      cartoonList.clear();
      cartoonList.addAll(list);
      if (cartoonList.isEmpty) {
        _showEmpty();
      } else {
        _showContent();
      }
    }, () {
      _showError();
    });
  }

  void _showContent() {
    isShowEmpty = false;
    isLoading = false;
    isShowError = false;
    update();
  }

  void _showLoading() {
    isShowEmpty = false;
    isLoading = true;
    isShowError = false;
    update();
  }

  void _showEmpty() {
    isShowEmpty = true;
    isLoading = false;
    isShowError = false;
    update();
  }

  void _showError() {
    isShowEmpty = false;
    isLoading = false;
    isShowError = true;
    update();
  }
}
